<?php
	require_once("oj-header.php");
	echo "<title>HUST Online Judge WebBoard</title>";
	$sql="SELECT `title`, `cid`, `pid`, `status`, `top_level` FROM `topic` WHERE `tid` = '".mysql_escape_string($_REQUEST['tid'])."' AND `status` <= 1";
	$result=mysql_query($sql) or die("Error! ".mysql_error());
	$rows_cnt = mysql_num_rows($result) or die("Error! ".mysql_error());
	$row= mysql_fetch_object($result);
	$isadmin = isset($_SESSION['administrator']);
?>


<div class="container"> 

<?php if ($isadmin){
	?><div style="font-size:80%; float:right"> Change sticky level to<?php $adminurl = "threadadmin.php?target=thread&tid={$_REQUEST['tid']}&action=";
	if ($row->top_level == 0) echo "[ <a href=\"{$adminurl}sticky&level=3\">Level Top</a> ] [ <a href=\"{$adminurl}sticky&level=2\">Level Mid</a> ] [ <a href=\"{$adminurl}sticky&level=1\">Level Low</a> ]"; else echo "[ <a href=\"{$adminurl}sticky&level=0\">Standard</a> ]";
	?> | <?php if ($row->status != 1) echo (" [ <a  href=\"{$adminurl}lock\">Lock</a> ]"); else echo(" [ <a href=\"{$adminurl}resume\">Resume</a> ]");
	?> | <?php echo (" [ <a href=\"{$adminurl}delete\">Delete</a> ]");
	?></div><?php }
?>

<ul class="breadcrumb">
<li>
	    <?php if ($cid!=null) echo "<a href=\"discuss.php?cid=".$cid."\">Contest ".$cid."</a>"; else echo "<a href=\"discuss.php\">论坛</a>";
if ($pid!=null && $pid!=0) echo " <span class='divider'>/</span> <a href=\"discuss.php?pid=".$pid."&cid=".$cid."\">P ".$pid."</a>";?>
<span class="divider"></span></li>
        <li class="active"><?php echo nl2br(htmlspecialchars($row->title));?></li>
   
</li>
</ul>

<h2><?php echo nl2br(htmlspecialchars($row->title));?></h2>

<div class="topic">
<?php
	$sql="SELECT `rid`, `author_id`, `time`, `content`, `status` FROM `reply` WHERE `topic_id` = '".mysql_escape_string($_REQUEST['tid'])."' AND `status` <=1 ORDER BY `rid` LIMIT 30";
	$result=mysql_query($sql) or die("Error! ".mysql_error());
	$rows_cnt = mysql_num_rows($result);
	$cnt=0;

	for ($i=0;$i<$rows_cnt;$i++){
		mysql_data_seek($result,$i);
		$row=mysql_fetch_object($result);
		$url = "threadadmin.php?target=reply&rid={$row->rid}&tid={$_REQUEST['tid']}&action=";
		$isuser = strtolower($row->author_id)==strtolower($_SESSION['user_id']);
?>

		
     <div class="reply">
		<div class="reply-header">
		    <a href="../userinfo.php?user=<?php echo $row->author_id?>"><?php echo $row->author_id; ?> </a> 回复于 <?php echo $row->time; ?>
			<?php if ($isuser || $isadmin)echo "<span class='pull-right'> <a href=".$url."delete>删除</a> </span>";?>
			<span class="pull-right"><?php echo $i+1;?>#</span>
		</div>
		<div class="well well-sm">
			<?php	if ($row->status == 0) echo $row->content;
					else {
						if ($isuser || $isadmin) echo $row->content;
					}
			?>
		</div>
		</div>
<?php
	}
?>
</div>

<?php if (isset($_SESSION['user_id'])){?>

<form class="add-reply form" action="post.php?action=reply" method="POST">
    <fieldset>
        <legend>回复</legend>
        <div class="form-group">
            <div>
			    <input type=hidden name=tid value=<?php echo $_REQUEST['tid'];?>>
                <textarea class="form-control" rows="8" id="content" name="content" cols="80"></textarea>
            </div>
        </div>
    </fieldset>
    <div class="form-group">
    <button type="submit" class="btn btn-primary">回复</button>
    </div>
</form>

<?php }
?>


</div>

<?php require_once("../oj-footer.php")?>
